package com.zzyang.cloud.controller;

import com.zzyang.cloud.pojo.entity.CommonResult;
import com.zzyang.cloud.pojo.entity.PaymentDO;
import com.zzyang.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import sun.plugin.util.UIUtil;

import java.util.UUID;

/**
 * TODO
 *
 * @author zhuoziyang
 * @date 2020/10/22 14:42
 */
@RestController
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String port;


    @GetMapping("/payment/get")
    public String get() {
        return "springcloud eureka port:" + port + " " + UUID.randomUUID();
    }

    @PostMapping("/payment")
    public CommonResult add(@RequestBody PaymentDO payment) {

        log.info(payment.toString());

        Integer result = paymentService.insert(payment);


        if (result >= 1) {
            return new CommonResult(200, "插入成功", result);
        } else {
            return new CommonResult(400, "插入失败");
        }

    }

    @GetMapping("/payment/{id}")
    public CommonResult getById(@PathVariable Long id) {
        PaymentDO byId = paymentService.getById(id);

        if (byId != null) {
            return new CommonResult(200, "查询成功6666666666", byId);
        } else {
            return new CommonResult(404, "查询失败,失败id:" + id);
        }

    }


}
